package org.ielts.service;

import org.ielts.domain.Mark;
import org.ielts.domain.log.OrderLessonLog;
import org.ielts.repository.OrderLessonLogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderLessonLogService {

	@Autowired
	OrderLessonLogRepository orderLessonLogRepository;

	@Transactional
	public OrderLessonLog resetOrderLesson(String id) {
		OrderLessonLog orderLessonLog = orderLessonLogRepository.findOne(id);

		orderLessonLog.setBeLate(false);
		orderLessonLog.setLeaveEarly(false);
		orderLessonLog.setMark(Mark.None);
		orderLessonLog.setValid(true);

		return orderLessonLog;
	}

	@Transactional
	public OrderLessonLog earlyOrderLesson(String id) {
		OrderLessonLog orderLessonLog = orderLessonLogRepository.findOne(id);

		orderLessonLog.setLeaveEarly(true);

		return orderLessonLog;
	}

	@Transactional
	public OrderLessonLog lateOrderLesson(String id) {
		OrderLessonLog orderLessonLog = orderLessonLogRepository.findOne(id);

		orderLessonLog.setBeLate(true);

		return orderLessonLog;
	}

	@Transactional
	public OrderLessonLog remarkOrderLesson(String id, String remark) {
		OrderLessonLog orderLessonLog = orderLessonLogRepository.findOne(id);

		orderLessonLog.setTeacherRemark(remark);

		return orderLessonLog;
	}

	@Transactional
	public OrderLessonLog markLesson(String id, Mark mark) {
		OrderLessonLog orderLessonLog = orderLessonLogRepository.findOne(id);

		orderLessonLog.setMark(mark);

		return orderLessonLog;
	}

	@Transactional
	public OrderLessonLog validOrderLesson(String id, boolean valid) {
		OrderLessonLog orderLessonLog = orderLessonLogRepository.findOne(id);

		orderLessonLog.setValid(valid);

		return orderLessonLog;
	}
}
